package com.njdj.gps.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class PageController extends BaseController {
	
	@RequestMapping(value="/home.do")
	public ModelAndView homeHandler(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws ServletException {
		
		return new ModelAndView("page/home");
	}
	
	@RequestMapping(value="/top.do")
	public ModelAndView topHandler(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws ServletException {
		model.put("userName", this.getUserName(request));
		model.put("fullName", this.getFullName(request));
		return new ModelAndView("page/top");
	}
	
	@RequestMapping(value="/left.do")
	public ModelAndView leftHandler(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws ServletException {
		String role = this.getRole(request);
		if(null == role || "".equals(role))
			return null;
		List<Map<String,Object>> leftMenuList = new ArrayList<Map<String,Object>>();
		Map<String,Object> leftMenu = new HashMap<String,Object>();
		leftMenu.put("name", "CarHis");
		leftMenu.put("url", "carhis.do");
		leftMenu.put("target", "mainFrame");
		leftMenuList.add(leftMenu);
		if("administrator".equals(role)){
			leftMenu = new HashMap<String, Object>();
			leftMenu.put("name", "TaskView");
			leftMenu.put("url", "taskview.do");
			leftMenu.put("target", "mainFrame");
			leftMenuList.add(leftMenu);
		}
		model.put("leftMenuList", leftMenuList);
		return new ModelAndView("page/left");
	}
	

}
